package com.news.gpb.controller;

import com.news.gpb.entity.Blog;
import com.news.gpb.service.BlogService;
import lombok.AllArgsConstructor;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@CrossOrigin("http://localhost:8080")
@RestController
public class BlogController {

    @Autowired
    BlogService blogService;

    @RequestMapping("writeBlog")
    Integer writeBlog(@RequestBody Blog blog)
    {
        return blogService.writeBlog(blog);
    }

    @RequestMapping("getBlog")
    List<Blog> getBlog(@RequestBody Blog blog)
    {
        return blogService.getBlog(blog.getUser_id());
    }

    @RequestMapping("countBlog")
    Integer countBlog(@RequestBody Blog blog)
    {
        return blogService.countBlog(blog.getUser_id());
    }

    @RequestMapping("deleteBlog")
    String deleteBlog(@RequestBody Blog blog)
    {
        return blogService.deleteBlog(blog);
    }
}
